package com.atwork.wuhua.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.atwork.wuhua.R;
import com.atwork.wuhua.utils.Util;

import butterknife.ButterKnife;

public abstract class BaseDialog extends Dialog {
    private Context mContext;
    Window dialogWindow;

    public BaseDialog(@NonNull Context context) {
        super(context, R.style.comment_dialog);
        mContext = context;
    }

    public interface OnDialogClick {
        void dialogClick(int switchButton);
    }

    public interface OnEdDialogClick {
        void dialogClick(String name, int switchButton);
    }

    public interface OnDialogResult {
        void dialogResult(int type);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(intiLayout());
        initWindowParams();
        ButterKnife.bind(this);
        initView();
    }

    private void initWindowParams() {
        dialogWindow = getWindow();
        // 获取屏幕宽、高用

        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = Util.getScreenWidch((Activity) mContext);
        dialogWindow.setGravity(Gravity.CENTER);
        dialogWindow.setAttributes(lp);
        this.setCanceledOnTouchOutside(true);
    }

    //设置弹出的位置  在子类的initview调用
    public void setGravityType(int gravity) {
        dialogWindow.setGravity(gravity);
    }

    //设置弹出动画效果  在子类的initview调用
    public void setWindowAnimations(int animations) {
        dialogWindow.setWindowAnimations(animations);
    }


    /**
     * 设置布局
     *
     * @return
     */
    public abstract int intiLayout();

    /**
     * 初始化布局
     */
    public abstract void initView();
}
